package jdbc;

import com.alibaba.druid.pool.DruidDataSource;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DBUtil {

    private static DruidDataSource druidDataSoure;

    static{
        druidDataSoure = new DruidDataSource();
        druidDataSoure.setUrl("jdbc:mysql://localhost:3306/tedu?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true");
        druidDataSoure.setUsername("root");
        druidDataSoure.setPassword("root");

        druidDataSoure.setInitialSize(5);//初始链接数量
        druidDataSoure.setMaxActive(20);//最大链接数量
      /*  try {
            Class.forName("com.mysql.cj.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }*/

    }
    public static Connection getConnection() throws SQLException {
        return druidDataSoure.getConnection();
        /*return DriverManager.getConnection("jdbc:mysql://localhost:3306/tedu?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true",
                "root",
                "root");*/
    }
}
